package com.casems.commons.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CaseData implements Comparable{
    private String name;
    private Integer value;
    private Integer value2;

    public CaseData(String name, Integer value){
        this.name = name;
        this.value = value;
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;
        }
        if(obj == null){
            return false;
        }
        if(getClass()!= obj.getClass()){
            return false;
        }
        CaseData other = (CaseData) obj;
        return this.getName().equals(((CaseData) obj).getName());
    }

    @Override
    public int hashCode(){
        return getName().hashCode();
    }

    @Override
    public int compareTo(Object o) {
        CaseData other = (CaseData) o;
        int[] one = convert(this.getName());
        int[] two = convert(other.getName());
        if(one[0]==two[0]){
            return one[1]-two[1];
        }
        return one[0]-two[0];
    }
    private int[] convert(String valuess){
        String[] values = valuess.split("-");
        int[] result = new int[values.length];
        for(int i = 0; i < values.length; i++){
            result[i] = Integer.parseInt(values[i]);
        }
        return result;
    }
}
